package zhuyun.code.launcheractivity.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_friend_verification.*
import zhuyun.code.launcheractivity.R
import zhuyun.code.launcheractivity.model.Constants
import zhuyun.code.launcheractivity.model.NetworkRequest
import zhuyun.code.launcheractivity.model.ResponseDataHandler
import zhuyun.code.launcheractivity.model.data.BaseResponse
import zhuyun.code.launcheractivity.model.data.CommonRequestBean

class FriendVerificationActivity : BaseActivity(),View.OnClickListener {
    private var userId = ""
    private var sourceId = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_friend_verification)
        userId = intent.getStringExtra(Constants.USER_ID)!!
        sourceId = intent.getIntExtra("sourceId", 1)
        tv_cancel.setOnClickListener(this)
        bt_send.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v!!.id){
            R.id.tv_cancel->{
                finish()
            }
            R.id.bt_send->{
                sendRequest()
            }

        }
    }

    private fun sendRequest(){
        NetworkRequest.applyAddFriend(userId,et_reason.text.toString().trim(),if(sc1.isChecked) 1 else 0,if(sc2.isChecked) 0 else 1
        ,et_name.text.toString().trim(),"",et_phone.text.toString().trim(),et_email.text.toString().trim(),sourceId
            ,object :ResponseDataHandler<CommonRequestBean>(){
                override fun onSuccess(
                    resultData: CommonRequestBean?,
                    baseResponse: BaseResponse<CommonRequestBean>
                ) {
                    val view = LayoutInflater.from(this@FriendVerificationActivity).inflate(R.layout.toast_verification,null)
                    val toast = Toast(this@FriendVerificationActivity)
                    toast.duration = Toast.LENGTH_LONG
                    toast.setGravity(Gravity.CENTER, 0, 0)
                    toast.view = view
                    //Toast.makeText(this@FriendVerificationActivity,"发送成功!",Toast.LENGTH_SHORT).show()
                    toast.show()
                    finish()
                }

                override fun onFailure(errMsg: String?) {

                }

            })
    }
}
